/**
 * Created by Administrator on 2021/3/2 0002.
 */
function sendRequest(url, param, fun, method) {
    if (isEmpty(method)) {
        method = 'POST'
    }
    $.ajax({
        type: method,
        async: false,
        url: url,
        data: param,
        dataType : "JSON",
        success: fun,
        error: errorFun
    });
}

function sendAsyncRequest(url, param, fun) {
    $.ajax({
        type: "post",
        url: url,
        data: param,
        dataType : "JSON",
        success: fun,
        error: errorFun
    });
}

function sendProcessRequest(url, param, fun, method) {
    if (isEmpty(method)) {
        method = 'POST'
    }
    $.ajax({
        type : 'POST',
        async : false,
        url : url,
        dataType : 'json',
        data : JSON.stringify(param),
        processData : false,
        contentType : "application/json",
        success : fun,
        error: errorFun
    });
}

function sendFileRequest(url, datas, beforeSendFun, fun, completeFun) {
    $.ajax({
        url: url,
        cache: false,
        type: 'post',
        processData: false,
        contentType: false,
        data: datas,
        beforeSend:beforeSendFun,
        success: fun,
        error: errorFun,
        complete: completeFun
    })
}

function errorFun(data) {
    // toastr.error(data.errInfo);
    console.log(data);
}

function successFun(data) {
    /*if (data.status == 'success') {
        toastr.success(data.msgInfo);
    } else {
        toastr.error(data.errInfo);
    }*/
    console.log(data);
}

/**
 * 判断表单域是否为空
 * @param data
 * @returns {Boolean}
 */
function isEmpty(data) {
    if (data == "" || data == null || $.trim(data) == "" || data == undefined || data == "undefined" || data == "null") {
        return true;
    } else {
        return false;
    }
}

$.fn.clearFileInput = function() {//清空file HTML控件的值
    return this.each(function() {
        if (/MSIE/.test(navigator.userAgent)) {
            $(this).replaceWith($(this).clone(true));
        } else {
            $(this).val('');
        }
    });
};